12345678910111213141516171819202122232425262728293031323334353637 |
- package config
- import (
- "eta/eta_mini_ht_api/models"
- "gorm.io/gorm/clause"
- "time"
- )
- // PermissionClassifyMapping 权限分类映射表
- type PermissionClassifyMapping struct {
- ID int `gorm:"column:id;primaryKey"`
- ClassifyID int `gorm:"column:classify_id"`
- PermissionID int `gorm:"column:permission_id"`
- CreatedTime time.Time `gorm:"column:created_time"`
- UpdatedTime time.Time `gorm:"column:updated_time"`
- }
- func (p *PermissionClassifyMapping) TableName() string {
- return "permission_classify_mapping"
- }
- func BatchInsertOrUpdateMapping(list []PermissionClassifyMapping) (err error) {
- db := models.Main()
- OnConflictFunc := clause.OnConflict{
- Columns: []clause.Column{{Name: "permission_id"}, {Name: "classify_id"}},
- DoUpdates: clause.AssignmentColumns([]string{"classify_id"}),
- }
- // 执行批量插入或更新操作
- err = db.Clauses(OnConflictFunc).Create(&list).Error
- return
- }
- func GetClassifyIdsByPermissionIds(permissionIds []int) (classifyIds []int, err error) {
- db := models.Main()
- err = db.Model(&PermissionClassifyMapping{}).Select("DISTINCT classify_id").Where("permission_id in ?", permissionIds).Scan(&classifyIds).Error
- return
- }
|