report.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_api/models"
  5. "hongze/hongze_api/utils"
  6. "html"
  7. "strings"
  8. "time"
  9. )
  10. //报告
  11. type ReportController struct {
  12. BaseAuthController
  13. }
  14. // @Title 日评详情
  15. // @Description 日评详情接口
  16. // @Param ReportId query int true "报告id"
  17. // @Success 200 {object} models.ReportDetailResp
  18. // @router /detail [get]
  19. func (this *ReportController) Detail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. user := this.User
  26. if user == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,用户信息为空"
  29. br.Ret = 408
  30. return
  31. }
  32. var status int
  33. var msg string
  34. reportId, err := this.GetInt("ReportId")
  35. if err != nil {
  36. br.Msg = "参数获取失败"
  37. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  38. return
  39. }
  40. if reportId <= 0 {
  41. br.Msg = "参数错误"
  42. br.ErrMsg = "参数错误,报告id小于等于0"
  43. return
  44. }
  45. report, err := models.GetReportById(reportId)
  46. if err != nil {
  47. br.Msg = "获取报告详情失败"
  48. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  49. return
  50. }
  51. if report == nil {
  52. status = 1
  53. msg = "报告不存在"
  54. }
  55. report.ContentSub = html.UnescapeString(report.ContentSub)
  56. report.Content = html.UnescapeString(report.Content)
  57. company, err := models.GetCompanyById(user.CompanyId)
  58. if err != nil && err.Error() != utils.ErrNoRow() {
  59. if err.Error() != utils.ErrNoRow() {
  60. br.Msg = "获取报告详情失败"
  61. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  62. return
  63. } else {
  64. status = 2
  65. msg = "您还未开通权限,如有需要请联系对口销售"
  66. report.Content = report.ContentSub
  67. }
  68. }
  69. if company == nil {
  70. status = 2
  71. msg = "您还未开通权限,如有需要请联系对口销售"
  72. report.Content = report.ContentSub
  73. } else {
  74. if company.Status == utils.COMPANY_STATUS_LOSE ||
  75. company.Status == utils.COMPANY_STATUS_FREEZE {
  76. status = 2
  77. msg = "您还未开通权限,如有需要请联系对口销售"
  78. report.Content = report.ContentSub
  79. }
  80. }
  81. reportType := "rddp"
  82. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType)
  83. if err != nil {
  84. if err.Error() != utils.ErrNoRow() {
  85. br.Msg = "获取报告详情失败"
  86. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  87. return
  88. } else {
  89. status = 2
  90. msg = "您还未开通权限,如有需要请联系对口销售"
  91. report.Content = report.ContentSub
  92. }
  93. }
  94. permissionMap := make(map[int]int)
  95. for _, v := range reportPermissionList {
  96. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  97. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  98. }
  99. }
  100. if _, ok := permissionMap[reportId]; !ok {
  101. tips := ""
  102. status = 2
  103. report.Content = report.ContentSub
  104. classifyNameSecond := report.ClassifyNameSecond
  105. if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
  106. strings.Contains(classifyNameSecond, "股债日评") ||
  107. strings.Contains(classifyNameSecond, "每日经济数据备忘录") {
  108. tips = "宏观"
  109. } else if strings.Contains(classifyNameSecond, "知白守黑日评") ||
  110. strings.Contains(classifyNameSecond, "动力煤数据点评") {
  111. tips = "黑色"
  112. } else if strings.Contains(classifyNameSecond, "化里化外日评") ||
  113. strings.Contains(classifyNameSecond, "EIA原油库存点评") ||
  114. strings.Contains(classifyNameSecond, "苯乙烯数据点评") ||
  115. strings.Contains(classifyNameSecond, "聚酯数据点评") {
  116. tips = "化工"
  117. } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") {
  118. tips = "有色"
  119. }
  120. msg = "您还未开通" + tips + "权限,如有需要请联系对口销售"
  121. }
  122. resp := new(models.ReportDetailResp)
  123. resp.Status = status
  124. resp.Msg = msg
  125. resp.Report = report
  126. //新增阅读记录
  127. if status == 0 {
  128. record := new(models.ReportViewRecord)
  129. record.UserId = user.UserId
  130. record.ReportId = reportId
  131. record.CreateTime = time.Now()
  132. err = models.AddReportViewRecord(record)
  133. if err != nil {
  134. go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  135. }
  136. }
  137. recommendList, err := models.GetRecommendList(reportId)
  138. if err != nil {
  139. br.Msg = "获取报告详情失败"
  140. br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
  141. return
  142. }
  143. recommendListLen := len(recommendList)
  144. for i := 0; i < recommendListLen; i++ {
  145. item := recommendList[i]
  146. recommendList[i].Content = html.UnescapeString(item.Content)
  147. recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
  148. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  149. if err != nil {
  150. br.Msg = "获取报告详情失败"
  151. br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error()
  152. return
  153. }
  154. if count > 0 {
  155. recommendList[i].HasPermission = 1
  156. }
  157. }
  158. resp.RecommendList = recommendList
  159. br.Ret = 200
  160. br.Success = true
  161. br.Msg = "获取成功"
  162. br.Data = resp
  163. }
  164. // @Title 日评列表
  165. // @Description 日评列表接口
  166. // @Param PageSize query int true "每页数据条数"
  167. // @Param CurrentIndex query int true "当前页页码,从1开始"
  168. // @Param ClassifyId query int true "分类id"
  169. // @Success 200 {object} models.ReportListResp
  170. // @router /list [get]
  171. func (this *ReportController) ListReport() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. user := this.User
  178. if user == nil {
  179. br.Msg = "请登录"
  180. br.ErrMsg = "请登录,用户信息为空"
  181. br.Ret = 408
  182. return
  183. }
  184. pageSize, _ := this.GetInt("PageSize")
  185. currentIndex, _ := this.GetInt("CurrentIndex")
  186. classifyId, _ := this.GetInt("ClassifyId")
  187. if classifyId <= 0 {
  188. br.Msg = "参数错误"
  189. br.ErrMsg = "参数错误,分类id小于等于0"
  190. return
  191. }
  192. var startSize int
  193. if pageSize <= 0 {
  194. pageSize = utils.PageSize20
  195. }
  196. if currentIndex <= 0 {
  197. currentIndex = 1
  198. }
  199. startSize = utils.StartIndex(currentIndex, pageSize)
  200. total, err := models.GetReportListCount(classifyId)
  201. if err != nil {
  202. br.Msg = "获取数据失败"
  203. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  204. return
  205. }
  206. list, err := models.GetReportList(classifyId, startSize, pageSize)
  207. if err != nil {
  208. br.Msg = "获取失败"
  209. br.ErrMsg = "获取失败,Err:" + err.Error()
  210. return
  211. }
  212. listLen := len(list)
  213. for i := 0; i < listLen; i++ {
  214. item := list[i]
  215. list[i].Content = html.UnescapeString(item.Content)
  216. list[i].ContentSub = html.UnescapeString(item.ContentSub)
  217. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  218. if err != nil {
  219. br.Msg = "获取失败"
  220. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  221. return
  222. }
  223. if count > 0 {
  224. list[i].HasPermission = 1
  225. }
  226. }
  227. page := models.GetPaging(currentIndex, pageSize, total)
  228. resp := new(models.ReportListResp)
  229. resp.Paging = page
  230. resp.List = list
  231. br.Ret = 200
  232. br.Success = true
  233. br.Msg = "获取成功"
  234. br.Data = resp
  235. }
  236. // @Title 新增报告浏览记录
  237. // @Description 新增报告浏览记录接口
  238. // @Param request body models.ReportRecordReq true "type json string"
  239. // @Success 200 新增成功
  240. // @router /addUpdateLabel [post]
  241. func (this *ReportController) AddUpdateLabelReport() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. user := this.User
  248. if user == nil {
  249. br.Msg = "请登录"
  250. br.ErrMsg = "请登录,用户信息为空"
  251. br.Ret = 408
  252. return
  253. }
  254. var req models.ReportRecordReq
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. if req.ReportId <= 0 {
  262. br.Msg = "参数错误"
  263. br.ErrMsg = "参数错误,报告id小于等于0"
  264. return
  265. }
  266. record := new(models.ReportViewLog)
  267. record.UserId = user.UserId
  268. record.ReportId = req.ReportId
  269. record.CreateTime = time.Now()
  270. err = models.AddReportViewLog(record)
  271. if err != nil {
  272. br.Msg = "获取数据失败"
  273. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  274. return
  275. }
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "新增成功"
  279. }
  280. // @Title 新增报告浏览记录
  281. // @Description 新增报告浏览记录接口
  282. // @Param request body models.ReportRecordReq true "type json string"
  283. // @Success 200 新增成功
  284. // @router /addViewRecord [post]
  285. func (this *ReportController) AddViewRecordReport() {
  286. br := new(models.BaseResponse).Init()
  287. defer func() {
  288. this.Data["json"] = br
  289. this.ServeJSON()
  290. }()
  291. user := this.User
  292. if user == nil {
  293. br.Msg = "请登录"
  294. br.ErrMsg = "请登录,用户信息为空"
  295. br.Ret = 408
  296. return
  297. }
  298. var req models.ReportRecordReq
  299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  300. if err != nil {
  301. br.Msg = "参数解析异常!"
  302. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  303. return
  304. }
  305. if req.ReportId <= 0 {
  306. br.Msg = "参数错误"
  307. br.ErrMsg = "参数错误,报告id小于等于0"
  308. return
  309. }
  310. record := new(models.ReportViewRecord)
  311. record.UserId = user.UserId
  312. record.ReportId = req.ReportId
  313. record.CreateTime = time.Now()
  314. err = models.AddReportViewRecord(record)
  315. if err != nil {
  316. br.Msg = "获取数据失败"
  317. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  318. return
  319. }
  320. br.Ret = 200
  321. br.Success = true
  322. br.Msg = "新增成功"
  323. }
  324. // @Title 新增音频阅读记录
  325. // @Description 新增音频阅读记录接口
  326. // @Param request body models.ReportRecordReq true "type json string"
  327. // @Success 200 新增成功
  328. // @router /addAudioRecord [post]
  329. func (this *ReportController) AddAudioRecord() {
  330. br := new(models.BaseResponse).Init()
  331. defer func() {
  332. this.Data["json"] = br
  333. this.ServeJSON()
  334. }()
  335. user := this.User
  336. if user == nil {
  337. br.Msg = "请登录"
  338. br.ErrMsg = "请登录,用户信息为空"
  339. br.Ret = 408
  340. return
  341. }
  342. var req models.ReportRecordReq
  343. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  344. if err != nil {
  345. br.Msg = "参数解析异常!"
  346. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  347. return
  348. }
  349. if req.ReportId <= 0 {
  350. br.Msg = "参数错误"
  351. br.ErrMsg = "参数错误,报告id小于等于0"
  352. return
  353. }
  354. record := new(models.ReportAudioRecord)
  355. record.UserId = user.UserId
  356. record.ReportId = req.ReportId
  357. record.CreateTime = time.Now()
  358. err = models.AddReportAudioRecord(record)
  359. if err != nil {
  360. br.Msg = "获取数据失败"
  361. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  362. return
  363. }
  364. br.Ret = 200
  365. br.Success = true
  366. br.Msg = "新增成功"
  367. }