query.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package chart_permission_chapter_mapping
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. // GetReportIdsByPermisssionIds 根据权限ID筛选报告ID, rddp 类型表示新后台新增的报告,区分老后台
  6. func GetReportIdsByPermisssionIds(permissionIds []int, researchType string) (reportIds []int, err error) {
  7. var charPermissionMapping []*ChartPermissionChapterMapping
  8. err = global.MYSQL["rddp"].Model(ChartPermissionChapterMapping{}).Select("DISTINCT report_chapter_type_id ").Where("chart_permission_id in (?) AND research_type = ? ", permissionIds, researchType).Scan(&charPermissionMapping).Error
  9. if err != nil {
  10. return
  11. }
  12. for _, v := range charPermissionMapping {
  13. reportIds = append(reportIds, v.ReportChapterTypeId)
  14. }
  15. return
  16. }
  17. // GetPermissionIdsByReportId 根据报告ID筛选出对应的权限
  18. func GetPermissionIdsByReportId(reportId int, researchType string) (permissionIds []int, err error) {
  19. var charPermissionMapping []*ChartPermissionChapterMapping
  20. err = global.MYSQL["rddp"].Model(ChartPermissionChapterMapping{}).
  21. Select("DISTINCT chart_permission_id").
  22. Where("report_chapter_type_id = ? and research_type = ? ", reportId, researchType).
  23. Scan(&charPermissionMapping).Error
  24. if err != nil {
  25. return
  26. }
  27. for _, v := range charPermissionMapping {
  28. permissionIds = append(permissionIds, v.ChartPermissionId)
  29. }
  30. return
  31. }
  32. // GetPermissionIdsByWeek 根据报告ID筛选出对应的权限
  33. func GetPermissionIdsByWeek() (permissionIds []int, err error) {
  34. var charPermissionMapping []*ChartPermissionChapterMapping
  35. err = global.MYSQL["rddp"].Model(ChartPermissionChapterMapping{}).
  36. Select("DISTINCT chart_permission_id").
  37. Where("research_type = 'week'").
  38. Scan(&charPermissionMapping).Error
  39. if err != nil {
  40. return
  41. }
  42. for _, v := range charPermissionMapping {
  43. permissionIds = append(permissionIds, v.ChartPermissionId)
  44. }
  45. return
  46. }