report.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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.CompanyType == 3 || company.CompanyType == 4 {
  75. status = 2
  76. msg = "您还未开通权限,如有需要请联系对口销售"
  77. report.Content = report.ContentSub
  78. }
  79. }
  80. reportType := "rddp"
  81. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType)
  82. if err != nil {
  83. if err.Error() != utils.ErrNoRow() {
  84. br.Msg = "获取报告详情失败"
  85. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  86. return
  87. } else {
  88. status = 2
  89. msg = "您还未开通权限,如有需要请联系对口销售"
  90. report.Content = report.ContentSub
  91. }
  92. }
  93. permissionMap := make(map[int]int)
  94. for _, v := range reportPermissionList {
  95. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  96. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  97. }
  98. }
  99. if _, ok := permissionMap[reportId]; !ok {
  100. tips := ""
  101. status = 2
  102. report.Content = report.ContentSub
  103. classifyNameSecond := report.ClassifyNameSecond
  104. if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
  105. strings.Contains(classifyNameSecond, "股债日评") ||
  106. strings.Contains(classifyNameSecond, "每日经济数据备忘录") {
  107. tips = "宏观"
  108. } else if strings.Contains(classifyNameSecond, "知白守黑日评") ||
  109. strings.Contains(classifyNameSecond, "动力煤数据点评") {
  110. tips = "黑色"
  111. } else if strings.Contains(classifyNameSecond, "化里化外日评") ||
  112. strings.Contains(classifyNameSecond, "EIA原油库存点评") ||
  113. strings.Contains(classifyNameSecond, "苯乙烯数据点评") ||
  114. strings.Contains(classifyNameSecond, "聚酯数据点评") {
  115. tips = "化工"
  116. } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") {
  117. tips = "有色"
  118. }
  119. msg = "您还未开通" + tips + "权限,如有需要请联系对口销售"
  120. }
  121. resp := new(models.ReportDetailResp)
  122. resp.Status = status
  123. resp.Msg = msg
  124. resp.Report = report
  125. //新增阅读记录
  126. if status == 0 {
  127. record := new(models.ReportViewRecord)
  128. record.UserId = user.UserId
  129. record.ReportId = reportId
  130. record.CreateTime = time.Now()
  131. err = models.AddReportViewRecord(record)
  132. if err != nil {
  133. go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  134. }
  135. }
  136. br.Ret = 200
  137. br.Success = true
  138. br.Msg = "获取成功"
  139. br.Data = resp
  140. }
  141. // @Title 日评列表
  142. // @Description 日评列表接口
  143. // @Param PageSize query int true "每页数据条数"
  144. // @Param CurrentIndex query int true "当前页页码,从1开始"
  145. // @Param ClassifyId query int true "分类id"
  146. // @Success 200 {object} models.ReportListResp
  147. // @router /list [get]
  148. func (this *ReportController) ListReport() {
  149. br := new(models.BaseResponse).Init()
  150. defer func() {
  151. this.Data["json"] = br
  152. this.ServeJSON()
  153. }()
  154. user := this.User
  155. if user == nil {
  156. br.Msg = "请登录"
  157. br.ErrMsg = "请登录,用户信息为空"
  158. br.Ret = 408
  159. return
  160. }
  161. pageSize, _ := this.GetInt("PageSize")
  162. currentIndex, _ := this.GetInt("CurrentIndex")
  163. classifyId, _ := this.GetInt("ClassifyId")
  164. if classifyId <= 0 {
  165. br.Msg = "参数错误"
  166. br.ErrMsg = "参数错误,分类id小于等于0"
  167. return
  168. }
  169. var startSize int
  170. if pageSize <= 0 {
  171. pageSize = utils.PageSize20
  172. }
  173. if currentIndex <= 0 {
  174. currentIndex = 1
  175. }
  176. startSize = utils.StartIndex(currentIndex, pageSize)
  177. total, err := models.GetReportListCount(classifyId)
  178. if err != nil {
  179. br.Msg = "获取数据失败"
  180. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  181. return
  182. }
  183. list, err := models.GetReportList(classifyId, startSize, pageSize)
  184. if err != nil {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取失败,Err:" + err.Error()
  187. return
  188. }
  189. listLen := len(list)
  190. for i := 0; i < listLen; i++ {
  191. item := list[i]
  192. list[i].Content = html.UnescapeString(item.Content)
  193. list[i].ContentSub = html.UnescapeString(item.ContentSub)
  194. count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
  195. if err != nil {
  196. br.Msg = "获取失败"
  197. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  198. return
  199. }
  200. if count > 0 {
  201. list[i].HasPermission = 1
  202. }
  203. }
  204. page := models.GetPaging(currentIndex, pageSize, total)
  205. resp := new(models.ReportListResp)
  206. resp.Paging = page
  207. resp.List = list
  208. br.Ret = 200
  209. br.Success = true
  210. br.Msg = "获取成功"
  211. br.Data = resp
  212. }
  213. // @Title 新增报告浏览记录
  214. // @Description 新增报告浏览记录接口
  215. // @Param request body models.ReportRecordReq true "type json string"
  216. // @Success 200 新增成功
  217. // @router /addUpdateLabel [post]
  218. func (this *ReportController) AddUpdateLabelReport() {
  219. br := new(models.BaseResponse).Init()
  220. defer func() {
  221. this.Data["json"] = br
  222. this.ServeJSON()
  223. }()
  224. user := this.User
  225. if user == nil {
  226. br.Msg = "请登录"
  227. br.ErrMsg = "请登录,用户信息为空"
  228. br.Ret = 408
  229. return
  230. }
  231. var req models.ReportRecordReq
  232. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  233. if err != nil {
  234. br.Msg = "参数解析异常!"
  235. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  236. return
  237. }
  238. if req.ReportId <= 0 {
  239. br.Msg = "参数错误"
  240. br.ErrMsg = "参数错误,报告id小于等于0"
  241. return
  242. }
  243. record := new(models.ReportViewLog)
  244. record.UserId = user.UserId
  245. record.ReportId = req.ReportId
  246. record.CreateTime = time.Now()
  247. err = models.AddReportViewLog(record)
  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.ReportRecordReq true "type json string"
  260. // @Success 200 新增成功
  261. // @router /addViewRecord [post]
  262. func (this *ReportController) AddViewRecordReport() {
  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.ReportRecordReq
  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. if req.ReportId <= 0 {
  283. br.Msg = "参数错误"
  284. br.ErrMsg = "参数错误,报告id小于等于0"
  285. return
  286. }
  287. record := new(models.ReportViewRecord)
  288. record.UserId = user.UserId
  289. record.ReportId = req.ReportId
  290. record.CreateTime = time.Now()
  291. err = models.AddReportViewRecord(record)
  292. if err != nil {
  293. br.Msg = "获取数据失败"
  294. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  295. return
  296. }
  297. br.Ret = 200
  298. br.Success = true
  299. br.Msg = "新增成功"
  300. }
  301. // @Title 新增音频阅读记录
  302. // @Description 新增音频阅读记录接口
  303. // @Param request body models.ReportRecordReq true "type json string"
  304. // @Success 200 新增成功
  305. // @router /addAudioRecord [post]
  306. func (this *ReportController) AddAudioRecord() {
  307. br := new(models.BaseResponse).Init()
  308. defer func() {
  309. this.Data["json"] = br
  310. this.ServeJSON()
  311. }()
  312. user := this.User
  313. if user == nil {
  314. br.Msg = "请登录"
  315. br.ErrMsg = "请登录,用户信息为空"
  316. br.Ret = 408
  317. return
  318. }
  319. var req models.ReportRecordReq
  320. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  321. if err != nil {
  322. br.Msg = "参数解析异常!"
  323. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  324. return
  325. }
  326. if req.ReportId <= 0 {
  327. br.Msg = "参数错误"
  328. br.ErrMsg = "参数错误,报告id小于等于0"
  329. return
  330. }
  331. record := new(models.ReportAudioRecord)
  332. record.UserId = user.UserId
  333. record.ReportId = req.ReportId
  334. record.CreateTime = time.Now()
  335. err = models.AddReportAudioRecord(record)
  336. if err != nil {
  337. br.Msg = "获取数据失败"
  338. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  339. return
  340. }
  341. br.Ret = 200
  342. br.Success = true
  343. br.Msg = "新增成功"
  344. }