query.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package report_chapter_permission_mapping
  2. import (
  3. "hongze/hongze_yb/global"
  4. "time"
  5. )
  6. // GetReportChapterListByPermissionIdsAndReportId
  7. // @Description: 根据报告ID和品种ID列表获取章节
  8. // @author: Roc
  9. // @datetime 2024-06-24 11:00:16
  10. // @param permissionIds []int
  11. // @param reportId int
  12. // @return reportChapterIdList []int
  13. // @return err error
  14. func GetReportChapterListByPermissionIdsAndReportId(permissionIds []int, reportId int) (reportChapterIdList []int, err error) {
  15. var items []*ReportChapterPermissionMapping
  16. obj := ReportChapterPermissionMapping{}
  17. err = global.MYSQL["rddp"].Table(obj.TableName()+" AS a ").
  18. Joins("INNER JOIN report_chapter AS b ON a.report_chapter_id = b.report_chapter_id").
  19. Select("DISTINCT a.report_chapter_id ").
  20. Where("a.chart_permission_id in (?) AND b.report_id = ? ", permissionIds, reportId).
  21. Scan(&items).Error
  22. if err != nil {
  23. return
  24. }
  25. for _, v := range items {
  26. reportChapterIdList = append(reportChapterIdList, v.ReportChapterID)
  27. }
  28. return
  29. }
  30. // ReportChapterPermissionMappingItem 报告章节的权限关系表
  31. type ReportChapterPermissionMappingItem struct {
  32. ReportChapterPermissionMappingID int `gorm:"primaryKey;column:report_chapter_permission_mapping_id" json:"report_chapter_permission_mapping_id"`
  33. ReportChapterID int `gorm:"column:report_chapter_id" json:"report_chapter_id"` // 报告章节的id
  34. ChartPermissionID int `gorm:"column:chart_permission_id" json:"chart_permission_id"` // 权限id
  35. TypeId int `gorm:"column:type_id" json:"type_id"` // 报告章节类型id
  36. CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
  37. }
  38. // GetReportChapterPermissionMappingItemListByReportId
  39. // @Description: 根据报告ID列表获取章节
  40. // @author: Roc
  41. // @datetime 2024-06-24 11:00:16
  42. // @param permissionIds []int
  43. // @param reportId int
  44. // @return reportChapterIdList []int
  45. // @return err error
  46. func GetReportChapterPermissionMappingItemListByReportId(reportId int) (items []*ReportChapterPermissionMappingItem, err error) {
  47. obj := ReportChapterPermissionMapping{}
  48. err = global.MYSQL["rddp"].Table(obj.TableName()+" AS a ").
  49. Joins("INNER JOIN report_chapter AS b ON a.report_chapter_id = b.report_chapter_id").
  50. Select("a.*,b.type_id").
  51. Where(" b.report_id = ? ", reportId).
  52. Scan(&items).Error
  53. return
  54. }
  55. // GetReportChapterListByReportId
  56. // @Description: 根据报告ID获取所有章节id
  57. // @author: Roc
  58. // @datetime 2024-06-24 11:02:23
  59. // @param reportId int
  60. // @return reportChapterIdList []int
  61. // @return err error
  62. func GetReportChapterListByReportId(reportId int) (reportChapterIdList []int, err error) {
  63. var items []*ReportChapterPermissionMapping
  64. obj := ReportChapterPermissionMapping{}
  65. err = global.MYSQL["rddp"].Table(obj.TableName()+" AS a ").
  66. Joins("INNER JOIN report_chapter AS b ON a.report_chapter_id = b.report_chapter_id").
  67. Select("DISTINCT report_chapter_id ").
  68. Where(" b.report_id = ? ", reportId).
  69. Scan(&items).Error
  70. if err != nil {
  71. return
  72. }
  73. for _, v := range items {
  74. reportChapterIdList = append(reportChapterIdList, v.ReportChapterID)
  75. }
  76. return
  77. }