permission_classify_mapping.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package config
  2. import (
  3. "eta/eta_mini_ht_api/models"
  4. "gorm.io/gorm/clause"
  5. "time"
  6. )
  7. // PermissionClassifyMapping 权限分类映射表
  8. type PermissionClassifyMapping struct {
  9. ID int `gorm:"column:id;primaryKey"`
  10. ClassifyID int `gorm:"column:classify_id"`
  11. PermissionID int `gorm:"column:permission_id"`
  12. CreatedTime time.Time `gorm:"column:created_time"`
  13. UpdatedTime time.Time `gorm:"column:updated_time"`
  14. }
  15. func (p *PermissionClassifyMapping) TableName() string {
  16. return "permission_classify_mapping"
  17. }
  18. func BatchInsertOrUpdateMapping(list []PermissionClassifyMapping) (err error) {
  19. db := models.Main()
  20. OnConflictFunc := clause.OnConflict{
  21. Columns: []clause.Column{{Name: "permission_id"}, {Name: "classify_id"}},
  22. DoUpdates: clause.AssignmentColumns([]string{"classify_id"}),
  23. }
  24. // 执行批量插入或更新操作
  25. err = db.Clauses(OnConflictFunc).Create(&list).Error
  26. return
  27. }
  28. func GetClassifyIdsByPermissionIds(permissionIds []int) (classifyIds []int, err error) {
  29. db := models.Main()
  30. err = db.Model(&PermissionClassifyMapping{}).Select("DISTINCT classify_id").Where("permission_id in ?", permissionIds).Scan(&classifyIds).Error
  31. return
  32. }