research_report.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package report
  2. import (
  3. "hongze/hongze_yb/models/tables/company_report_permission"
  4. "hongze/hongze_yb/models/tables/research_report"
  5. "hongze/hongze_yb/utils"
  6. )
  7. func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
  8. //获取报告详情
  9. reportInfo, err := research_report.GetByResearchReportId(researchReportId)
  10. if err != nil {
  11. return
  12. }
  13. reportType := reportInfo.Type
  14. //这些个报告需要做权限校验
  15. if utils.InArray(reportInfo.Type, []string{"month", "two_week", "other"}) {
  16. list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
  17. if tmpErr != nil {
  18. err = tmpErr
  19. return
  20. }
  21. for _, v := range list {
  22. if reportInfo.ResearchReportID == v.ReportChapterTypeId {
  23. hasPermission = true
  24. break
  25. }
  26. }
  27. if !hasPermission {
  28. //permissionName, tmpErr := company_report_permission.GetPermissionNameByReportId(reportInfo.ResearchReportID, reportType)
  29. //if tmpErr != nil {
  30. // err = tmpErr
  31. // return
  32. //}
  33. return
  34. }
  35. }
  36. researchReportTypeList := make([]*company_report_permission.ResearchReportTypeList, 0)
  37. tmpResearchReportTypeList, err := company_report_permission.GetResearchReportType(reportInfo.ResearchReportID, userId, reportInfo.Type)
  38. if err != nil {
  39. return
  40. }
  41. reportDate := reportInfo.ResearchReportDate
  42. for _, v := range tmpResearchReportTypeList {
  43. if reportDate.Before(v.PauseStartTime) || reportDate.After(v.PauseEndTime) {
  44. researchReportTypeList = append(researchReportTypeList, v)
  45. }
  46. }
  47. result = ResearchReportInfo{
  48. ResearchReportInfo: reportInfo,
  49. ResearchReportTypeList: researchReportTypeList,
  50. HasMenu: 1,
  51. }
  52. if len(researchReportTypeList) <= 0 {
  53. } else if len(researchReportTypeList) == 1 {
  54. //只有一个章节,即没有目录的时候,需要直接返回章节详情
  55. result.HasMenu = 0
  56. researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContent(researchReportTypeList[0].ResearchReportTypeId)
  57. if tmpErr != nil {
  58. return
  59. }
  60. result.ResearchReportTypeContentList = researchReportTypeContent
  61. }
  62. return
  63. }
  64. type ResearchReportInfo struct {
  65. ResearchReportInfo *research_report.ResearchReport `json:"research_report_info"`
  66. ResearchReportTypeList []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
  67. HasMenu int `json:"has_menu"`
  68. ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情"`
  69. }