custom_query.go 3.6 KB

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