custom_query.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package company_report_permission
  2. import (
  3. "hongze/hongze_yb/global"
  4. "strings"
  5. "time"
  6. )
  7. type ReportChapterTypeIdList struct {
  8. ReportChapterTypeId uint64
  9. }
  10. // GetReportVarietyList
  11. func GetReportVarietyList(userId uint64, reportType string) (list []*ReportChapterTypeIdList, err error) {
  12. var condition string
  13. whereVals := make([]interface{}, 0)
  14. if reportType != "" {
  15. condition += ` and cpcm.research_type = ? `
  16. whereVals = append(whereVals, reportType)
  17. }
  18. sql := ` SELECT cpcm.report_chapter_type_id FROM company_report_permission crp
  19. INNER JOIN chart_permission_chapter_mapping cpcm ON crp.chart_permission_id = cpcm.chart_permission_id
  20. INNER JOIN wx_user wu ON wu.company_id = crp.company_id
  21. WHERE wu.user_id = ? `
  22. sql += condition
  23. sql += ` GROUP BY cpcm.report_chapter_type_id `
  24. err = global.DEFAULT_MYSQL.Raw(sql, userId, whereVals).Scan(&list).Error
  25. return
  26. }
  27. type ResearchReportTypeList struct {
  28. ResearchReportTypeId int
  29. ResearchReportId int
  30. ResearchReportTypeTitle string
  31. TypeId int
  32. Edit int
  33. Trend int
  34. ReportChapterTypeKey string
  35. ReportChapterTypeThumb string
  36. BannerUrl string
  37. ReportChapterTypeName string
  38. Sort string
  39. EditImgUrl string
  40. PauseStartTime time.Time
  41. PauseEndTime time.Time
  42. LastUpdatedTime time.Time
  43. }
  44. // 获取研究报告的章节详情
  45. func GetResearchReportType(researchReportId, userId uint64, reportType string) (list []*ResearchReportTypeList, err error) {
  46. var condition string
  47. whereVals := make([]interface{}, 0)
  48. //如果是周报,并且是H5页面
  49. if "week" == reportType && userId > 0 {
  50. condition += ` and rrt.edit=1 `
  51. reportChapterTypeList, tmpErr := GetReportVarietyList(userId, reportType)
  52. if tmpErr != nil {
  53. err = tmpErr
  54. return
  55. }
  56. if len(reportChapterTypeList) > 0 {
  57. reportChapterTypeIdList := make([]uint64, 0)
  58. for _, v := range reportChapterTypeList {
  59. reportChapterTypeIdList = append(reportChapterTypeIdList, v.ReportChapterTypeId)
  60. }
  61. condition += ` and rct.report_chapter_type_id in (?) `
  62. whereVals = append(whereVals, reportChapterTypeIdList)
  63. }
  64. }
  65. if strings.Contains("day,week", reportType) {
  66. condition += ` and rct.is_show=1 `
  67. }
  68. sql := `select
  69. rrt.research_report_type_id,
  70. rrt.research_report_id,
  71. rrt.research_report_type_title,
  72. rrt.type_id,
  73. rrt.edit,
  74. rrt.trend,
  75. rct.report_chapter_type_key,
  76. rct.report_chapter_type_thumb,
  77. rct.banner_url,
  78. rct.report_chapter_type_name,
  79. rct.sort,
  80. rct.edit_img_url,
  81. rct.pause_start_time,
  82. rct.pause_end_time,
  83. rrt.last_updated_time
  84. from research_report_type rrt
  85. left JOIN report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  86. where rrt.research_report_id = ? `
  87. sql += condition
  88. sql += ` order by rct.sort,rrt.research_report_type_id `
  89. err = global.DEFAULT_MYSQL.Raw(sql, researchReportId, whereVals).Scan(&list).Error
  90. return
  91. }
  92. type PermissionName struct {
  93. ChartPermissionName string
  94. ResearchType string
  95. }
  96. // GetPermissionNameByReportId
  97. func GetPermissionNameByReportId(reportChapterTypeId uint64, researchType string) (item PermissionName, err error) {
  98. sql := `SELECT b.chart_permission_name,a.research_type FROM chart_permission_chapter_mapping AS a
  99. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  100. WHERE a.report_chapter_type_id = ? AND a.research_type=?' LIMIT 1 `
  101. err = global.DEFAULT_MYSQL.Raw(sql, reportChapterTypeId, researchType).Scan(&item).Error
  102. return
  103. }